#===istalismanplugin===
# -*- coding: utf-8 -*-

# $Revision: 52 $
# $Author: rchiganov@gmail.com $
# $Date: 2013-07-29 04:17:07 +0000 (Mon, 29 Jul 2013) $

#---------------------------------------------------------------------------------------------------

import urllib2

#---------------------------------------------------------------------------------------------------

def afor_run ( ptype, psource, pparameters ):
	try:
		lrequest = urllib2.Request('http://skio.ru/quotes/humour_quotes.php')
		lrequest.add_header = ('User-agent', 'Vika-bot rev%s' % BOT_VER['botver']['rev'].decode('utf-8'))
		lpage  = urllib2.urlopen(lrequest)
		ltext  = lpage.read()
		lindex = ltext.find('<form id="qForm" method="post"><div align="center">')
		ltext  = ltext[lindex + len('<form id="qForm" method="post"><div align="center">'):]
		lindex = ltext.find('</div>')
		ltext  = ltext[0:lindex]
		reply(ptype, psource, unicode(ltext,'windows-1251'))
	except:
		reply(ptype, psource, u'что-то сломалось...')

#---------------------------------------------------------------------------------------------------

register_command_handler(afor_run, 'афор', ['инфо', 'все'], 0, 'Показывает случайный афоризм с ресурса skio.ru', 'афор', ['афор'])

#---------------------------------------------------------------------------------------------------
